String.prototype.stripslashes = function () {
    var str = this;
    str = str.replace(/\\'/g, '\'');
    str = str.replace(/\\"/g, '"');
    str = str.replace(/\\0/g, '\0');
    str = str.replace(/\\\\/g, '\\');
    return str;
};

$(function () {
    $(".Dialog .Layout").on("click", function () {
        new Dialog().close();
    });


});


var App = {
    setSession: function (key, value, success, error) {
        $.ajax({
            type: 'get',
            url: BaseUrl + 'create-variable?var=' + key + '&data=' + value,
            success: function () {
                if (typeof success == 'function') {
                    success();
                }
            }, error: function (a, b) {
                if (typeof error == 'function') {
                    error(a, b);
                }
            }
        });
    },
    getSession: function (key, success, error) {
        $.ajax({
            type: 'get',
            url: BaseUrl + 'get-variable?var=' + key,
            success: function (data) {
                if (typeof success == 'function') {
                    success(data);
                }
            }, error: function (a, b) {
                if (typeof error == 'function') {
                    error(a, b);
                }
            }
        });
    },
    soundEffect: function (filename) {
        var audio = new Audio(BaseUrl + 'public/sound/' + filename + '.mp3');
        audio.play();
    },
    Timestamp: {
        getDateTime: function () {
            return Math.round((new Date()).getTime() / 1000);
        },
        getDateTimeMilliseconds: function () {
            return new Date().getTime();
        }
    },
    mobileDetect: function () {
        var checker = {
            iphone: navigator.userAgent.match(/(iPhone|iPod|iPad)/),
            blackberry: navigator.userAgent.match(/BlackBerry/),
            android: navigator.userAgent.match(/Android/),
            windowphone: navigator.userAgent.match(/Windows Phone/),
            moto: navigator.userAgent.match(/MOTOROLA/),
            Windows: navigator.userAgent.match(/IEMobile/),
            Nokia: navigator.userAgent.match(/Nokia/),
            opera: navigator.userAgent.match(/Opera Mini/)
        };
        if (checker.android) {
            return "Android";
        } else if (checker.iphone) {
            return "iOS";
        } else if (checker.blackberry) {
            return "blackberry";
        } else if (checker.windowphone) {
            return "windowphone";
        } else if (checker.moto) {
            return "moto";
        } else if (checker.Windows) {
            return "Windows";
        } else if (checker.opera) {
            return "opera";
        } else {
            return "Other";
        }
    }

};
App.applicationOs = App.mobileDetect();

var TextPanel = {
    init: function () {
        $(".Panel_Cancel").on("tap", function () {
            $(".UI_TextPanel textarea").val("");
            TextPanel.close();
        });

        $(".UI_TextPanel button").UI_AddClassHover("hover");

    },
    isOpen: function () {
        return $(".UI_TextPanel").is(":visible");
    },
    close: function () {
        $(".UI_TextPanel").hide();
    },
    show: function (done) {
        $(".UI_TextPanel").show();
        if (typeof done == 'function') {
            done();
        }
    }
}


var Dialog = function () {
    this.showPoster = function (options) {

        var html = '<div class="Poster zoomIn animated">\n\
                        <div class="image" style="background: url(' + options.poster + ') no-repeat"></div>\n\
                        <div class="info">\n\
                            <div class="logo" style="background: url(' + options.channel_logo + ') no-repeat"></div>\n\
                            <div class="schedule"><span class="icon-clock"></span>' + options.time + '</div>\n\
                        </div>\n\
                    </div>';
        $(".Dialog .Inner").html(html).parent().show();
    };
    this.close = function () {
        $(".Dialog .Inner").empty().parent().fadeOut();
    };
};

var Status = function () {
    this.push = function (text) {
        var textW = $(".status .text").width();
        $(".status").width(textW);
        $(".statusbar .status .text").addClass("before");
        var w = $(".before").width();
        $(".statusbar .status .hidden").append('<div class="text current" style="transform:translateX(' + (w + 30) + 'px">' + text + '</div>');
        setTimeout(function () {
            $(".before").css({transform: 'translateX(-' + w + 'px)', transition: 'linear 5s'});
            $(".current").css({transform: 'translateX(0px)', transition: 'linear 5s'});
            setTimeout(function () {
                $(".before").remove();
                $(".current").removeClass("current").addClass("flash animated");
            }, 5000);
        }, 200);
    };
};